import Vue from 'vue'
import Vuex from 'vuex'
import axios from "axios"
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)

export default new Vuex.Store({
  plugins: [createPersistedState()],
  state: {
    token: '',
    userInfo: {},
  },
  mutations: {
    updateToken (state, token) {
      state.token = token
    },
    updateUserInfo (state, payload) {
      state.userInfo = payload
    }
  },
  actions: {
    async updataInfo (context) {
      const { data: res } = await axios('/my/userinfo')
      context.commit('updateUserInfo', res.data)
    }
  },
})
